'''
Created on 2011-04-27

@author: kacper

'''
import logging
import inspect
from butterfly.aliasing import logger
from config.config import getRoot

# create logger with 'spam_application'
logger = logging.getLogger('Default app')
logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages

fh = logging.FileHandler(getRoot()+'/logs/default.log')
fh.setLevel(logging.DEBUG)

# create console handler with a higher log level
#ch = logging.StreamHandler()
#ch.setLevel(logging.ERROR)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
#ch.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(fh)
#logger.addHandler(ch)

def logFun(fn):
    args = inspect.getargspec(fn)
    logger.info( "Enter function " + fn.__name__ + "\n args: " + str(args)  )
    return fn

def instLogFun(log):
    
    def logFun(fn):
        args = inspect.getargspec(fn)
        log( "Enter function " + fn.__name__ + "\n args: " + str(args)  )
        return fn

    return logFun


def log(*args):
    for arg in args:
        logger.info(str(arg))
    
def instLog(inf):
    
    def log(*args):
        logger.info(inf)
        s = "\n".join(map(str,args))
        logger.info(s)

    return log